﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VOEISHubPushServiceClient
{
    class ServiceNotifications : IServiceNotifications
    {
        private bool _SMTPMailEnabled;
        private string _SMTPServer;
        private int _SMTPPort;
        private string _SMTPSender;
        private bool _SMTPSSLEnabled;
        private string _SMTPRecipients;
        private bool _SMTPRequiresAuthentication;
        private string _SMTPUserName;
        private string _SMTPPassword;

        public bool SMTPMailEnabled
        {
            get
            {
                return _SMTPMailEnabled;
            }
            set
            {
                _SMTPMailEnabled = value;
            }
        }

        public string SMTPServer
        {
            get
            {
                return _SMTPServer;
            }
            set
            {
                _SMTPServer = value;
            }
        }

        public int SMTPPort
        {
            get
            {
                return _SMTPPort;
            }
            set
            {
                _SMTPPort = value;
            }
        }

        public string SMTPSender
        {
            get
            {
                return _SMTPSender;
            }
            set
            {
                _SMTPSender = value;
            }
        }

        public bool SMTPSSLEnabled
        {
            get
            {
                return _SMTPSSLEnabled;
            }
            set
            {
                _SMTPSSLEnabled = value;
            }
        }

        public string SMTPRecipients
        {
            get
            {
                return _SMTPRecipients;
            }
            set
            {
                _SMTPRecipients = value;
            }
        }

        public bool SMTPRequiresAuthentication
        {
            get
            {
                return _SMTPRequiresAuthentication;
            }
            set
            {
                _SMTPRequiresAuthentication = value;
            }
        }

        public string SMTPUserName
        {
            get
            {
                return _SMTPUserName;
            }
            set
            {
                _SMTPUserName = value;
            }
        }

        public string SMTPPassword
        {
            get
            {
                return "********";
            }
            set
            {
                _SMTPPassword = value;
            }
        }

        public ServiceNotifications()
        {
            ServiceConfigurationManager scm = new ServiceConfigurationManager();

            Dictionary<string, string> NotificationsDictionary = new Dictionary<string,string>();
            NotificationsDictionary = scm.ReadNotificationSettings();

            _SMTPMailEnabled = bool.Parse(NotificationsDictionary["MailEnabled"]);
            _SMTPServer = NotificationsDictionary["MailServer"];
            _SMTPPort = int.Parse(NotificationsDictionary["MailPort"]);
            _SMTPSender = NotificationsDictionary["ServiceEmail"];
            _SMTPSSLEnabled = bool.Parse(NotificationsDictionary["MailSSL"]);
            _SMTPRecipients = NotificationsDictionary["MailRecipients"];
            _SMTPRequiresAuthentication = bool.Parse(NotificationsDictionary["MailAuthenticate"]);
            _SMTPUserName = NotificationsDictionary["MailUserName"];
            _SMTPPassword = NotificationsDictionary["MailPassword"];
        }

        public void LoadServiceNotifications(string TemplatePath)
        {
            ServiceConfigurationManager scm = new ServiceConfigurationManager();

            Dictionary<string, string> NotificationsDictionary = new Dictionary<string, string>();
            scm.ApplicationConfigPath = TemplatePath;
            NotificationsDictionary = scm.ReadNotificationSettings();

            _SMTPMailEnabled = bool.Parse(NotificationsDictionary["MailEnabled"]);
            _SMTPServer = NotificationsDictionary["MailServer"];
            _SMTPPort = int.Parse(NotificationsDictionary["MailPort"]);
            _SMTPSender = NotificationsDictionary["ServiceEmail"];
            _SMTPSSLEnabled = bool.Parse(NotificationsDictionary["MailSSL"]);
            _SMTPRecipients = NotificationsDictionary["MailRecipients"];
            _SMTPRequiresAuthentication = bool.Parse(NotificationsDictionary["MailAuthenticate"]);
            _SMTPUserName = NotificationsDictionary["MailUserName"];
            _SMTPPassword = NotificationsDictionary["MailPassword"];
        }
    }
}
